package watercups.operators;

import templates.Operator;
import watercups.states.WaterCupState;

public class Empty2to1 implements Operator<WaterCupState>{

	public int getOperatorNumber() {
        return 6;
    }

    public WaterCupState execute(WaterCupState s) {
		int ct = 3 - s.getCapacity1(); // cantitatea ce trebuie transferata
		int ctrans; // cantitatea transferata
		
    	if(ct < s.getCapacity2()) {
			ctrans = ct;
			s.setCapacity1(s.getCapacity1()+ctrans);
			s.setCapacity2(s.getCapacity2()-ctrans);
    		return new WaterCupState(s.getCapacity1(),s.getCapacity2());
			}
    	else {
			ctrans = s.getCapacity2();
			s.setCapacity1(s.getCapacity1()+ctrans);
			s.setCapacity2(s.getCapacity2()-ctrans);
    		return new WaterCupState(s.getCapacity1(),s.getCapacity2());
		}
    }

    public String toString(){
        return "Emptying second cup into cup nr 1";
    }

	public boolean available(WaterCupState s) {
		if((s.getCapacity2()>0) && (s.getCapacity2()<=4) && (s.getCapacity1()>3))
			return true;
		return false;
	}
	
}
